# ******************************************************************
# Cobbler managed dhcpd.conf file
#
# generated from cobbler dhcp.conf template ($date)
# Do NOT make changes to /etc/dhcpd.conf. Instead, make your changes
# in /etc/cobbler/dhcp.template, as /etc/dhcpd.conf will be
# overwritten.
#
# /etc/cobbler/dhcp.template is managed by puppet
#
# ******************************************************************

ddns-update-style interim;

allow booting;
allow bootp;

ignore client-updates;
set vendorclass = option vendor-class-identifier;

<% unless @dhcp_interfaces == '' or @dhcp_interfaces.nil? -%>
<% @dhcp_interfaces.each do |iface| -%>
subnet <%= instance_variable_get("@network_#{iface}") %> netmask <%= instance_variable_get("@netmask_#{iface}") %> {
    option domain-name          "<%= @domain %>";
    option subnet-mask          <%= instance_variable_get("@netmask_#{iface}") %>;
    option domain-name-servers  <%=
if @nameservers.kind_of?(Array)
   @nameservers.join(", ")
elsif (@nameservers.kind_of?(String) && @nameservers != '' )
   @nameservers
else
   puts("127.0.0.1")
end %>;
    option routers              <%= instance_variable_get("@ipaddress_#{iface}").match(/\d+\.\d+\.\d+/) %>.1;
    filename                    "/pxelinux.0";<% if @dhcp_dynamic_range == 1 then %>
    range dynamic-bootp         <%= instance_variable_get("@ipaddress_#{iface}").match(/\d+\.\d+\.\d+/) %>.100 <%= instance_variable_get("@ipaddress_#{iface}").match(/\d+\.\d+\.\d+/) %>.200;<% end %>
    default-lease-time          21600;
    max-lease-time              43200;
    next-server                 $next_server;
}
<% end -%>
<% end -%>
<% unless @dhcp_subnets == '' or @dhcp_subnets.nil? -%>
<% @dhcp_subnets.each do |dhcp_subnet| -%>
<% dhcp_subnet_split   = dhcp_subnet.split('/') -%>
subnet <%= dhcp_subnet_split[0] %> netmask <%= dhcp_subnet_split[1] %> {
    option domain-name          "<%= @domain %>";
    option subnet-mask          <%= dhcp_subnet_split[1]%>;
    option domain-name-servers  <%=
if @nameservers.kind_of?(Array)
   @nameservers.join(", ")
elsif (@nameservers.kind_of?(String) && @nameservers != '' )
   @nameservers
else
   puts("127.0.0.1")
end %>;
    option routers              <%= dhcp_subnet_split[0].match(/\d+\.\d+\.\d+/) %>.<%= dhcp_subnet_split[0].sub(/\d+\.\d+\.\d+\./, '').to_i + 1 %>;
    filename                    "/pxelinux.0";
    default-lease-time          21600;
    max-lease-time              43200;
    next-server                 $next_server;
}
<% end -%>
<% end -%>

#for dhcp_tag in $dhcp_tags.keys():
    ## group could be subnet if your dhcp tags line up with your subnets
    ## or really any valid dhcpd.conf construct ... if you only use the
    ## default dhcp tag in cobbler, the group block can be deleted for a
    ## flat configuration
# group for Cobbler DHCP tag: $dhcp_tag
group {
        #for mac in $dhcp_tags[$dhcp_tag].keys():
            #set iface = $dhcp_tags[$dhcp_tag][$mac]
    host $iface.name {
        hardware ethernet $mac;
        #if $iface.ip_address:
        fixed-address $iface.ip_address;
        #end if
        #if $iface.hostname:
        option host-name "$iface.hostname";
        #end if
        #if $iface.subnet:
        option subnet-mask $iface.subnet;
        #end if
        #if $iface.gateway:
        option routers $iface.gateway;
        #end if
        filename "$iface.filename";
        ## Cobbler defaults to $next_server, but some users
        ## may like to use $iface.system.server for proxied setups
        next-server $next_server;
        ## next-server $iface.next_server;
    }
        #end for
}
#end for

